<template>
  <div>
    <!--    班组form模糊查询-->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="班组类型" prop="name">
        <el-select v-model="queryParams.typeId" placeholder="请选择班组类型" clearable>
          <el-option
            v-for="dict in dict.type.sys_class_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="班组编码" prop="head">
        <el-input
          v-model="queryParams.teamCode"
          placeholder="请输入班组编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班组名称" prop="tel">
        <el-input
          v-model="queryParams.teamName"
          placeholder="请输入班组名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!--班组列表-->
    <el-table v-loading="loading" :data="marketList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="班组id" align="center" prop="teamId" />
      <el-table-column label="班组编码" align="center" prop="teamCode" />
      <el-table-column label="班组名称" align="center" prop="teamName" />
      <el-table-column label="所属分类" align="typeId" prop="typeId">
        <template v-slot="scope">
          <dict-tag :options="dict.type.sys_class_type" :value="scope.row.typeId"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="班组id" align="center" prop="id" />
      <el-table-column label="轮班方式" align="center" prop="aroundId" />
    </el-table>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="addBanzu">确 定</el-button>
    </div>


    <!--    班组分页-->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />



  </div>
</template>

<script>
import {listMarket,addbanzu} from "@/api/scheduling/team";

export default {
  name: "Teammember",
  dicts: ['sys_class_type'],
  props: {
    team: {
       type: Array,
     }
  },
  watch:{
    team: {
      handler: function (newTeam, oldTeam) {
        if (newTeam) {
          console.log(newTeam,"newTeam")
          this.bancid=newTeam[0].id;
          console.log(this.bancid,"bancid")
        }
      },
      immediate: true
    }
  },
  data() {
    return {
      aroundId:undefined,
      bancid:undefined,
      marketList:[],
      flaging:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        head: null,
        tel: null
      },
    }
  }, methods: {
    addBanzu(row){
      console.log(row+":aaa")
      const ids = row.teamId || this.ids;
      addbanzu(ids,this.bancid).then(r=>{
        if(r.code==200){
          this.$modal.msgSuccess("新增成功");
          this.getList();
          window.location.href="http://localhost/scheduling/plan";
        }else{
          this.$modal.msgError(r.msg);
        }

      })
    },
    //班组
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    //班组
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    // 班组多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.teamId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    /** 查询班组列表 */
    getList() {
      this.loading = true;
      listMarket(this.queryParams).then(response => {
        this.marketList = response.rows;
        console.log(this.marketList,"123")
        this.total = response.total;
        this.loading = false;
      });
    },
  }, created() {

    this.getList();
  }
}
</script>

<style scoped>

</style>
